package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.buried.Self;
import com.cardbaobao.cardbabyclient.buried.SelfUtils;
import com.cardbaobao.cardbabyclient.ui.activity.web.AgreementWebViewActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.model.CreditApplyRecord;
import com.cardbaobao.cardbabyclient.utils.DensityUtil;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

/**
 * Description: 信用卡申请记录
 * Created by FHW
 * on 2017/7/05
 */

public class CreditApplyRecordRcAdapter extends CommonRecyclerAdapter<CreditApplyRecord> {
    private long enterTime;
    private String currentPageId;
    private String prePageId;
    public CreditApplyRecordRcAdapter(Context context) {
        super(context, null, R.layout.item_credit_apply_record);
    }

    public void setBuriedInfo(long enterTime, String currentPageId, String prePageId){
        this.enterTime=enterTime;
        this.currentPageId=currentPageId;
        this.prePageId=prePageId;
    }

    @Override
    public void convert(final CommonRecyclerHolder holder, final CreditApplyRecord item) {

//        if (holder.position == 0) {
//            holder.getView(R.id.ll_top).setVisibility(View.VISIBLE);
//        } else {
//            holder.getView(R.id.ll_top).setVisibility(View.GONE);
//        }
        if(holder.getAdapterPosition()==0){
            try{
                ViewGroup.MarginLayoutParams layoutParams=
                        (ViewGroup.MarginLayoutParams) holder.getView(R.id.rl_item).getLayoutParams();
                layoutParams.topMargin= DensityUtil.dp2px(16);
                holder.getView(R.id.rl_item).setLayoutParams(layoutParams);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        //信用卡logo
        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL + item.getImage(), (ImageView) holder.getView(R.id.iv_pic));
        holder.setTextViewText(R.id.tv_name, item.getName());
        holder.setTextViewText(R.id.tv_time, item.getApplyDateTime().split(" ")[0]);
//        holder.setTextViewText(R.id.tv_state, item.getSTATUS());

//        if ("未受理".equals(item.getSTATUS())) {
//            holder.setImageRes(R.id.iv_state, R.mipmap.icon_apply_record_yellow);
//        } else if ("已办理".equals(item.getSTATUS())) {//可查询
//            holder.setImageRes(R.id.iv_state, R.mipmap.icon_apply_record_blue);
//        } else {//已受理
//            holder.setImageRes(R.id.iv_state, R.mipmap.icon_apply_record_pink);
//        }

        holder.getView(R.id.rl_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if ("已办理".equals(item.getSTATUS()) && !item.getProgressUrl().equals("")) {
                if (!item.getProgressUrl().equals("")) {
                    //查看点击事件
                    SelfUtils.buriedClickData(Self.Action.app_click_credit_card_apply_record_item,
                            Self.Action.app_click_credit_card_apply_record_item_des,
                            enterTime,
                            currentPageId,
                            prePageId);
                    Intent mIntent = new Intent();
                    mIntent.setClass(mContext, AgreementWebViewActivity.class);
                    mIntent.putExtra("title", "办卡进度查询");
                    mIntent.putExtra("webUrl", item.getProgressUrl());
                    mContext.startActivity(mIntent);
                }
            }
        });

    }

}
